package com.kanche.bigbaby.collection;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;

import com.kanche.bigbaby.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;

//import com.kkche.bss.R;


public class TaskPhotoEsotericaActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_task_photo_esoterica);
//        TextView btn_left_count = (TextView) findViewById(R.id.btn_left_count);
//        btn_left_count.setText(R.string.fa_arrow_left);
//        btn_left_count.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                finish();
//            }
//        });
//        TextView title = (TextView) findViewById(R.id.title);
//        title.setText("拍照教程");
        final ImageView im_take_photo = (ImageView) findViewById(R.id.im_take_photo);
        //获取Android屏幕的服务
        final WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
        final int windowWidth = wm.getDefaultDisplay().getWidth();
        DisplayImageOptions options;
        options = new DisplayImageOptions.Builder()
                .imageScaleType(ImageScaleType.NONE)
                .build();
        ImageLoader.getInstance().loadImage("assets://image/take_photo_teaching1080.jpg", options, new SimpleImageLoadingListener() {

            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                super.onLoadingComplete(imageUri, view, loadedImage);
                float width = loadedImage.getWidth();
                float hight = loadedImage.getHeight();

                float scale = windowWidth/width;
                int newhight = (int) (hight*scale);
                im_take_photo.setImageBitmap(scale(loadedImage,windowWidth,newhight));
            }
        });
    }

    private static Bitmap scale(Bitmap bitmap, int width, int hight) {
        Bitmap mBitmap = Bitmap.createScaledBitmap(bitmap, width, hight, true);
        return mBitmap;
    }
}
